<template>
  <!-- body -->
  <div class="body">
    <!-- 搜索历史 -->
    <div class="tag-container">
      <p class="tag-title">搜索历史</p>
      <div class="tag-box">
        <span class="tag-item" v-for="(h, i) in historyArray" :key="i" @click="searchKeyWord(h)">{{
          h
        }}</span>
      </div>
    </div>
    <!-- 热门标签 -->
    <div class="tag-container">
      <p class="tag-title">{{ searchDetail.name }}</p>
      <div class="tag-box" v-html="searchDetail.content"></div>
    </div>
  </div>
</template>

<script>
import { SearchPageAPI } from "@/apis";
export default {
  data() {
    return {
      searchDetail: {},
    };
  },
  mounted() {
    this.getSearch();
  },
  computed: {
    // 历史记录
    historyArray() {
      return JSON.parse(localStorage.searchHistory || "[]");
    },
  },
  methods: {
    // 网络请求
    async getSearch() {
      let { data } = await this.$http(SearchPageAPI);
      this.searchDetail = data;
    },
    // 
    searchKeyWord(kw){
      this.$router.push(`/search/result/${kw}`)
      this.value
    }
  },
};
</script>

<style lang="scss" scoped>
.body {
  padding: 0 15px;
  background-color: #fff;
  .tag-container {
    padding: 20px 0 15px;
    margin: 0 0 -10px;
    .tag-title {
      color: var(--book-name-font-black);
      font-size: 14px;
      line-height: 24px;
      margin-bottom: 15px;
    }
    .tag-box {
      display: flex;
      width: 345px;
      flex-wrap: wrap;
      .tag-item {
        color: var(--more-font-grey);
        background-color: var(--more-bg-white);
        font-size: 14px;
        padding: 6px 15px;
        margin: 0 10px 10px 0;
        border-radius: 2px;
      }
    }
  }
}
</style>